package org.example.SlApi;



import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.example.RestClient;
import org.example.utils.ReadConf;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;


public class QykbApi {
    public static void main(String[] args) throws UnsupportedEncodingException {    //企业开办
        qykbApi();
    }
    public static int qykbApi() throws UnsupportedEncodingException {
        // 登录并更新cookies
        loginAndUpdateCookies();//        updateCookiesFromLoginResponse(loginAndUpdateCookies);
//        System.out.println("Stored Cookies: " + getCookies());
//        String cookieHeader = getCookieHeader();
//        System.out.println("Cookie Header: " + cookieHeader);
//        loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");

        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI


            Map<String, String> formParams = new HashMap<>();
        formParams.put("method", "enterFrfw");
        formParams.put("currentPage", "1");
        formParams.put("currentPage_wdqm", "1");
        formParams.put("currentPage_wdhy", "1");

        formParams.put("qylx", "qy");


        Response response = givenWithCookies()

//                .cookies(cookies)
                .params(formParams)

                .post("unite.do?method=enterQykb"); // 注意：可能需要有效的 CSRF Token

        int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
        List<String> cookies = response.getHeaders().getValues("Set-Cookie");

        for (String cookie : cookies) {
            System.out.println("Set-Cookie Header: " + cookie);
        }
        System.out.println(statusCode);
        String body = response.getBody().asString();
//       System.out.println(body);

        return statusCode;
    }

}


